package com.gccloud.design.service.impl;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gccloud.design.dao.SdSchPriRelDao;
import com.gccloud.design.dao.SdSchemeDao;
import com.gccloud.design.dto.PriRelDto;
import com.gccloud.design.dto.SdSchPriRelDto;
import com.gccloud.design.entity.SdSchPriRelEntity;
import com.gccloud.design.service.SdSchPriRelSevice;
import com.gccloud.design.vo.PriRelVO;
import com.gccloud.starter.common.dto.SearchDTO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author mengyu
 * @date 2020/12/26 13:55
 */
@Service
public class SdSchPriRelSeviceImpl extends ServiceImpl<SdSchPriRelDao, SdSchPriRelEntity> implements SdSchPriRelSevice {

    @Resource
    private SdSchemeDao sdSchemeDao;

    @Resource
    private SdSchPriRelDao sdSchPriRelDao;

    @Override
    public void deleteSchemeAndPriRel(Integer schemeId) {
        sdSchPriRelDao.deleteByschemeId(schemeId);
        sdSchemeDao.deleteById(schemeId);
    }

    @Override
    public Map<String, Object> getPriRelList(SearchDTO searchDTO) {
        Map<String, Object> map = new HashMap<>(8);
        Page<SdSchPriRelDto> page = new Page<>(searchDTO.getCurrent(), searchDTO.getSize());
        List<SdSchPriRelDto> priRelList = sdSchPriRelDao.getPriRelList(Integer.parseInt(searchDTO.getSearchKey()), page);
        map.put("list", priRelList);
        map.put("total", page.getTotal());
        return map;
    }

    @Override
    public List<PriRelVO> getPriRel(int schemeId) {
        return sdSchPriRelDao.getPriRel(schemeId);
    }

    @Override
    public List<PriRelDto> getPriRelAttr(String schemeId) {
        return sdSchPriRelDao.getPriRelAttr(schemeId);
    }

}
